

#include <cstdlib>
#include <string.h>
#include <iostream>

#include "io_data.h"
#include "video_encoder_core.h"

extern "C" {

#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libavutil/avutil.h>
#include <libswscale/swscale.h>
#include <libavutil/imgutils.h>

}

int Decodec264ToYUV() {

    std::cout << "Decodec264ToYUV" << std::endl;

    const std::string input_file_name  = "/home/hjie/download/h264_file.h264";
    const std::string output_file_name = "./output.yuv";


    std::cout << "input file name : " << input_file_name   << std::endl;
    std::cout << "output file name : " << output_file_name << std::endl;

    int result = open_input_output_file(input_file_name, output_file_name);
    if (result == -1) {

        close_input_output();
        return EXIT_FAILURE;
    }
    result = init_video_decoder();

    if (result < 0) {


        std::cout << "init video encoder failed" << std::endl;
        return EXIT_FAILURE;
    }
    result = decoding();
    if (result < 0) {

        std::cout << "encoding failed" << std::endl;
        return EXIT_FAILURE;
    }
    return EXIT_SUCCESS;
}

int EncodecYUVTo264() {

    std::cout << "EncodecYUVTo264" << std::endl;

    const std::string input_file_name  = "";
    const std::string output_file_name = "";
    const std::string codec_name       = "";


    std::cout << "input file name : " << input_file_name   << std::endl;
    std::cout << "output file name : " << output_file_name << std::endl;
    std::cout << "codec name : " << codec_name << std::endl;


    int result = open_input_output_file(input_file_name, output_file_name);
    if (result == -1) {

        close_input_output();
        return EXIT_FAILURE;
    }

    result = init_video_encoder("libx264");

    if (result < 0) {


        std::cout << "init video encoder failed" << std::endl;
        return EXIT_FAILURE;
    }
    result = encoding(50);
    if (result < 0) {

        std::cout << "encoding failed" << std::endl;
        return EXIT_FAILURE;
    }
    return EXIT_SUCCESS;
}

int main() {


    Decodec264ToYUV();

    return EXIT_SUCCESS;
}